package cn.javaSong.controller;


import cn.javaSong.common.ResponseHelper;
import cn.javaSong.common.ResponseModel;
import cn.javaSong.entity.WyySong;
import cn.javaSong.mapper.WyySongMapper;
import cn.javaSong.payload.SelectSongName;
import cn.javaSong.service.IWyySongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dakai
 * @since 2024-10-24
 */
@RestController
@RequestMapping("/wyysong")
public class WyySongController {

    @Autowired
    private IWyySongService iSongService;

    @Resource
    private WyySongMapper wyySongMapper;

    @Value("${img-url}")
    private String imgUrl;

    /**
     * 新增
     * @param song
     * @return
     */
    @PostMapping("/save")
    public ResponseModel addImg(@RequestBody WyySong song) {
        return iSongService.addImg(song);
    }

    @PostMapping("/select")
    public ResponseModel selectSong(@RequestBody SelectSongName request) {
        return ResponseHelper.buildResponseModel(iSongService.selectSong(request));
    }

    @PostMapping("/oneList")
    public String oneList() {
        WyySong song = wyySongMapper.oneRandImg();
        return imgUrl + song.getLyricName();
    }
}
